package com.ericsson.resourceplanner.dao.entity;

import java.io.Serializable;

import javax.persistence.*;

import java.util.List;


/**
 * The persistent class for the EMPLOYEE database table.
 * 
 */
@Entity
@NamedQuery(name="fetchEmployee",query="select e from Employee e where e.signumId=:signum")
public class Employee implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name="EMPLOYEE_ID_GENERATOR", sequenceName="ORDER_SEQUENCE")
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="EMPLOYEE_ID_GENERATOR")
	private long id;

	@Column(name="EMP_NAME")
	private String empName;

	private String password;

	@Column(name="SIGNUM_ID")
	private String signumId;

	//bi-directional many-to-one association to AuditLog
	@OneToMany(mappedBy="employee")
	private List<AuditLog> auditLogs;

	//bi-directional many-to-one association to EmployeeProject
	@OneToMany(mappedBy="employee")
	private List<EmployeeProject> employeeProjects;

	//bi-directional many-to-one association to EmployeeRole
	@OneToMany(mappedBy="employee")
	private List<EmployeeRole> employeeRoles;
	
	@Transient
	private boolean enabled;

	public Employee() {
	}

	public long getId() {
		return this.id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getEmpName() {
		return this.empName;
	}

	public void setEmpName(String empName) {
		this.empName = empName;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSignumId() {
		return this.signumId;
	}

	public void setSignumId(String signumId) {
		this.signumId = signumId;
	}

	public List<AuditLog> getAuditLogs() {
		return this.auditLogs;
	}

	public void setAuditLogs(List<AuditLog> auditLogs) {
		this.auditLogs = auditLogs;
	}

	public AuditLog addAuditLog(AuditLog auditLog) {
		getAuditLogs().add(auditLog);
		auditLog.setEmployee(this);

		return auditLog;
	}

	public AuditLog removeAuditLog(AuditLog auditLog) {
		getAuditLogs().remove(auditLog);
		auditLog.setEmployee(null);

		return auditLog;
	}

	public List<EmployeeProject> getEmployeeProjects() {
		return this.employeeProjects;
	}

	public void setEmployeeProjects(List<EmployeeProject> employeeProjects) {
		this.employeeProjects = employeeProjects;
	}

	public EmployeeProject addEmployeeProject(EmployeeProject employeeProject) {
		getEmployeeProjects().add(employeeProject);
		employeeProject.setEmployee(this);

		return employeeProject;
	}

	public EmployeeProject removeEmployeeProject(EmployeeProject employeeProject) {
		getEmployeeProjects().remove(employeeProject);
		employeeProject.setEmployee(null);

		return employeeProject;
	}

	public List<EmployeeRole> getEmployeeRoles() {
		return this.employeeRoles;
	}

	public void setEmployeeRoles(List<EmployeeRole> employeeRoles) {
		this.employeeRoles = employeeRoles;
	}

//	public EmployeeRole addEmployeeRole(EmployeeRole employeeRole) {
//		getEmployeeRoles().add(employeeRole);
//		employeeRole.setEmployee(this);
//
//		return employeeRole;
//	}

	public EmployeeRole removeEmployeeRole(EmployeeRole employeeRole) {
		getEmployeeRoles().remove(employeeRole);
		employeeRole.setEmployee(null);

		return employeeRole;
	}

	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((auditLogs == null) ? 0 : auditLogs.hashCode());
		result = prime * result + ((empName == null) ? 0 : empName.hashCode());
		result = prime
				* result
				+ ((employeeProjects == null) ? 0 : employeeProjects.hashCode());
		result = prime * result
				+ ((employeeRoles == null) ? 0 : employeeRoles.hashCode());
		result = prime * result + (enabled ? 1231 : 1237);
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		result = prime * result
				+ ((signumId == null) ? 0 : signumId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Employee other = (Employee) obj;
		if (auditLogs == null) {
			if (other.auditLogs != null)
				return false;
		} else if (!auditLogs.equals(other.auditLogs))
			return false;
		if (empName == null) {
			if (other.empName != null)
				return false;
		} else if (!empName.equals(other.empName))
			return false;
		if (employeeProjects == null) {
			if (other.employeeProjects != null)
				return false;
		} else if (!employeeProjects.equals(other.employeeProjects))
			return false;
		if (employeeRoles == null) {
			if (other.employeeRoles != null)
				return false;
		} else if (!employeeRoles.equals(other.employeeRoles))
			return false;
		if (enabled != other.enabled)
			return false;
		if (id != other.id)
			return false;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if (!password.equals(other.password))
			return false;
		if (signumId == null) {
			if (other.signumId != null)
				return false;
		} else if (!signumId.equals(other.signumId))
			return false;
		return true;
	}


}